package com.company3.students;

import java.util.List;

public class addstudent {
    /**
     * 添加学生对象
     *
     * @param id 学号
     * @param name 姓名
     * @param age 年龄
     * @param listStudents 存放学生对象的List
     */
    public static void addStudent(int id, String name, int age,List<student> listStudents) {
        student newStudent = new student(id, name, age);
        boolean flag = listStudents.contains(newStudent);
        if (flag) {
            System.out.printf("学号%d已经存在，添加失败\n", id);

        } else {
            listStudents.add(newStudent);
            System.out.printf("%s添加成功\n", name);
        }
    }
}
